﻿using System.Diagnostics;

namespace System.Modules.Logging.EventViewer
{
    /// <summary>
    /// Event Viewer Log Service
    /// </summary>
    public class EventViewerLogService
    {
        /// <summary>
        /// This method Logs message to event Viewer
        /// </summary>
        /// <param name="source"></param>
        /// <param name="message"></param>
        /// <param name="type"></param>
        public static bool LogEvent(string source, string message, EventLogEntryType type)
        {
            try
            {
                const string S_LOG = "Application";
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, S_LOG);
                }

                EventLog.WriteEntry(source, message, type);
            }
            catch
            {
                return false;
            }
            return true;
        }
    }
}
